package com.retirement.access.controller;


import com.retirement.access.domain.OldAccess;
import com.retirement.access.dto.AccessDto;
import com.retirement.access.dto.AccessPageDto;
import com.retirement.access.service.IOldAccessService;
import com.retirement.access.vo.AccessPageVo;
import com.retirement.common.core.controller.BaseController;
import com.retirement.common.core.domain.AjaxResult;
import com.retirement.common.core.page.TableDataInfo;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lijy
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/access")
@RequiredArgsConstructor
public class OldAccessController extends BaseController {

    private final IOldAccessService iOldAccessService;

    @PostMapping
    @ApiOperation("新增走访记录")
    public AjaxResult addAccess(@RequestBody AccessDto dto){
        return AjaxResult.success(iOldAccessService.addAccess(dto));
    }

    @GetMapping("/page")
    @ApiOperation("分页查询走访记录")
    public TableDataInfo getAccessPage(AccessPageDto dto){
        startPage();
        return getDataTable(iOldAccessService.getPage(dto));
    }

    @GetMapping("/{id}")
    @ApiOperation("查询记录详情")
    public AccessPageVo getDetail(@PathVariable("id") String id){
        return iOldAccessService.getDetail(id);
    }

    @PutMapping
    @ApiOperation("修改走访记录")
    public AjaxResult updaateAccess(@RequestBody OldAccess dto){
        return AjaxResult.success(iOldAccessService.updateAccess(dto));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除走访记录")
    public AjaxResult deleteAccess(@PathVariable("id") String id){
        return AjaxResult.success(iOldAccessService.removeById(id));
    }

}
